/*
 * Copyright 2011-2015 SICHUAN FENGTAI
 * 
 *
 */
package com.enjoychange.common.tool;

import java.math.BigDecimal;
/**
 * 数字转换成希望的小数位数
 * @author Administrator
 *
 */
public class NumberFormatUtil {
   public final static int default_fraction_2=2;//两位小数
   /**
    * @param number 被转换的数值
    * @param fraction 小数位数
    * @return
    * 2008-10-23-liuyang
    */
   public static double formatStr(double number,int fraction){
	  
	  BigDecimal bigDecimal = new BigDecimal(number);
	  return bigDecimal.setScale(fraction, BigDecimal.ROUND_HALF_UP).doubleValue();

   }
   /**
    * see above
    * @param number
    * @param fraction
    * @return
    * 2008-10-23-liuyang
    */
   public static String format(double number,int fraction){
	   java.text.NumberFormat  formater  =  java.text.DecimalFormat.getInstance();  
	   formater.setMaximumFractionDigits(fraction);  
	   formater.setMinimumFractionDigits(fraction);	   
	   return formater.format(number);
   }
}
